class Solution(object):
    def getHint(self, secret, guess):
        """
        :type secret: str
        :type guess: str
        :rtype: str
        """
        dict1, dict2 = {}, {}
        length = len(secret)
        A, B = 0, 0
        for i in range(length):
            if secret[i]!=guess[i]:
                ch1 = int(secret[i])
                if ch1 not in dict1:
                    dict1.update({ch1:0})
                dict1[ch1]+=1
                ch2 = int(guess[i])
                if ch2 not in dict2:
                    dict2.update({ch2:0})
                dict2[ch2]+=1
            else:
                A += 1
        for i in range(10):
            if i in dict1 and i in dict2:
                B += min(dict1[i], dict2[i])
        return "{}A{}B".format(A, B)

print(Solution().getHint("1807", "7810"))